$(function(){
    $('.del').live('click',function(){
        var v=confirm('确定要删除此栏目吗?');
        if(!v){
            return false;
        }
    });
    //这里实现栏目异步加载

    $.post(ajurl,function(data){
        if(data.status==1){
            var code='';
            for(var i=0;i<data.rows.length;i++){
                var bgcolor=(i%2==0)?'#fff':'#eee';
                code += '<tr bgcolor="'+bgcolor+'" height="100%" width="100%">';
                code += "<td width='50' class='border'>"+data['rows'][i]['cid']+"</td>";
                var s=data['rows'][i]['pid']!=0?'|':'';
                code += "<td class='border'><a class='tt' href="+arcindex+"/cid/"+data['rows'][i]['cid']+">"+s+data['rows'][i]['html']+data['rows'][i]['catname']+"</td>";
                code += "<td width='50' class='border'>"+data['rows'][i]['total']+"</td>";
                code += "<td class='border' width='300'>"
                code += "<a href="+addshow+"/cid/"+data['rows'][i]['cid']+">[增加子类]</a>";
                code += "<a href="+moveshow+"/cid/"+data['rows'][i]['cid']+"/n/"+data['rows'][i]['catname']+">[移动]</a>";
                var add=data['rows'][i]['issend']==0?"<a href="+arcadd+"/cid/"+data['rows'][i]['cid']+" class='move'>[添加文章]</a>":'';
                code += add;
                code += "<a href="+editshow+"/cid/"+data['rows'][i]['cid']+">[编辑]</a>";
                code += "<a href="+del+"/cid/"+data['rows'][i]['cid']+" class='del'>[删除栏目]</a>";
                code += '</td></tr>';
            }
            code += "<tr class='p'><td colspan='6'>"+data['page']+"</td></tr>";
            $('tbody.slow').prepend(code).hide().fadeIn('slow');
        }else{
            alert('数据加载失败，请刷新');
        }

    },'json');

    //有分页时，点击分页的异步实现
    $('.p a').live('click',function(){
        $.post($(this).attr('href'),function(data){
            if(data.status==1){
                var code='';
                for(var i=0;i<data.rows.length;i++){
                    code += '<tr>';
                    code += "<td width='50' class='border'>"+data['rows'][i]['cid']+"</td>";
                    var s=data['rows'][i]['pid']!=0?'|':'';
                    code += "<td class='border'><a class='tt' href="+arcindex+"/cid/"+data['rows'][i]['cid']+">"+s+data['rows'][i]['html']+data['rows'][i]['catname']+"</td>";
                    ;
                    code += "<td width='50' class='border'>"+data['rows'][i]['total']+"</td>";
                    code += "<td class='border' width='300'>"
                    code += "<a href="+addshow+"/cid/"+data['rows'][i]['cid']+">[增加子类]</a>";
                    code += "<a href="+moveshow+"/cid/"+data['rows'][i]['cid']+"/n/"+data['rows'][i]['catname']+">[移动]</a>";
                    var add=data['rows'][i]['issend']==0?"<a href="+arcadd+"/cid/"+data['rows'][i]['cid']+" class='move'>[添加文章]</a>":'';
                    code += add;
                    code += "<a href="+editshow+"/cid/"+data['rows'][i]['cid']+">[编辑]</a>";
                    code += "<a href="+del+"/cid/"+data['rows'][i]['cid']+" class='del'>[删除栏目]</a>";
                    code += '</td></tr>';
                }
                code += "<tr class='p'><td colspan='3'>"+data['page']+"</td></tr>";
                $('tbody.slow tr').remove();
                $('tbody.slow').prepend(code).hide().fadeIn('slow');
            }
        },'json')
        return false;
    });

})

